import 'package:flutter/material.dart';
import 'package:flutter_09_game/base/widget/base_get_builder.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/config/app_routes.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/user/app_user_manager.dart';
import 'package:flutter_09_game/utils/utils_other.dart';
import 'package:flutter_09_game/widgets/appbar/common_app_bar.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'profile_trc_manager_logic.dart';

class ProfileTrcManagerPage extends StatelessWidget {
  ProfileTrcManagerPage({super.key});

  final ProfileTrcManagerLogic logic = Get.put(ProfileTrcManagerLogic());

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<ProfileTrcManagerLogic>(
      appBar: CommonAppBar(
        title: LocaleKeys.bindBettingAddress.tr,
        actions: [
          GestureDetector(
            onTap: () {
              AppUserManager().showServiceSheet();
            },
            child: AutoImage(
              Assets.commonServiceBtn,
              width: 32.w,
            ),
          ),
          10.horizontalSpace,
        ],
      ),
      builder: (_) {
        return Padding(
          padding: EdgeInsets.all(16.w),
          child: Column(
            children: [
              Container(
                width: double.infinity,
                height: 195.w,
                padding: EdgeInsets.all(20.w),
                decoration: const BoxDecoration(
                  image: DecorationImage(
                      image: AssetImage(Assets.mineTrcBg), fit: BoxFit.cover),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        GestureDetector(
                          onTap: () {
                            logic.verifyFundPassword().then((value) {
                              if (value == true) {
                                UtilsOther.copyMemberId(AppUserManager()
                                        .user
                                        .value
                                        ?.withdrawAddress ??
                                    "");
                              }
                            });
                          },
                          child: AutoImage(
                            Assets.mineTrcCopy,
                            width: 32.w,
                          ),
                        ),
                        12.horizontalSpace,
                        GestureDetector(
                          onTap: () {
                            logic.verifyFundPassword().then((value) {
                              if (value == true) {
                                Get.toNamed(AppRoutes.profileEditTrcPage);
                              }
                            });
                          },
                          child: AutoImage(
                            Assets.mineTrcSetting,
                            width: 32.w,
                          ),
                        ),
                        12.horizontalSpace,
                        GestureDetector(
                          onTap: () {
                            logic
                                .verifyFundPassword(isDelete: true)
                                .then((value) {
                              if (value == true) {
                                // Get.back();
                                Get.offNamed(AppRoutes.profileBindAddressPage);
                              }
                            });
                          },
                          child: AutoImage(
                            Assets.mineTrcDelete,
                            width: 32.w,
                          ),
                        ),
                        // 12.horizontalSpace,
                      ],
                    ),
                    const Spacer(),
                    Row(
                      children: [
                        // AutoImage(
                        //   Assets.commonTrxTag,
                        //   width: 20.w,
                        // ),
                        // 8.horizontalSpace,
                        Text(
                          'TRC20',
                          style: TextStyle(
                              color: AppColor.textPrimary.withOpacity(0.94),
                              fontSize: 20.sp,
                              fontWeight: FontWeight.w900),
                        )
                      ],
                    ),
                    12.verticalSpaceFromWidth,
                    Text(
                      LocaleKeys.address.tr,
                      style: TextStyle(
                          color: AppColor.textPrimary.withOpacity(0.7),
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500),
                    ),
                    4.verticalSpaceFromWidth,
                    Obx(() {
                      return Row(
                        children: [
                          Flexible(
                              child: Text(
                            logic.showAddress.value == false
                                ? UtilsOther.formatWithdrawAddress(
                                    AppUserManager()
                                        .user
                                        .value
                                        ?.withdrawAddress)
                                : (AppUserManager()
                                        .user
                                        .value
                                        ?.withdrawAddress ??
                                    ''),
                            style: TextStyle(
                                color: AppColor.textPrimary.withOpacity(0.94),
                                fontSize: 20.sp,
                                height: 0.9,
                                fontWeight: FontWeight.w600),
                          )),
                          12.horizontalSpace,
                          Visibility(
                              visible: (AppUserManager()
                                          .user
                                          .value
                                          ?.withdrawAddress ??
                                      '')
                                  .isNotEmpty,
                              child: GestureDetector(
                                onTap: () {
                                  if (logic.showAddress.value == false) {
                                    logic.verifyFundPassword().then((value) {
                                      if (value == true) {
                                        logic.showAddress.value = true;
                                      }
                                    });
                                  } else {
                                    logic.showAddress.value = false;
                                  }
                                },
                                child: AutoImage(
                                  logic.showAddress.value == false
                                      ? Assets.mineVisibleClose
                                      : Assets.mineVisibleOpen,
                                  width: 24.w,
                                ),
                              ))
                        ],
                      );
                    }),
                    // formatWithdrawAddress
                  ],
                ),
              )
            ],
          ),
        );
      },
    );
  }
}
